#include "LedData.h"

#include <float.h>
#include <limits.h>

#include "ComDefine.h"

bool CLedData::IsCommNormal()
{
    return (0 == m_uCommState);
}

bool CLedData::IsCommFault()
{
    return (1 == m_uCommState);
}

bool CLedData::IsRunning()
{
    return (0 == m_uRunState);
}

bool CLedData::IsStopped()
{
    return (1 == m_uRunState);
}

bool CLedData::IsFault()
{
    return (1 == m_uFaultState);
}

bool CLedData::IsNoFault()
{
    return (0 == m_uFaultState);
}

bool CLedData::IsAlarm()
{
    return (1 == m_uAlarmState);
}

bool CLedData::IsNoAlarm()
{
    return (0 == m_uAlarmState);
}

bool CLedData::IsOpening()
{
    return (1 == m_uSwitchState);
}

bool CLedData::IsClosed()
{
    return (0 == m_uSwitchState);
}

//获取***的显示文本
QString CLedData::GetCommStateText()
{
    if (0xFFFF == m_uCommState)
    {
        return QObject::tr("---");
    }
    else if (1 == m_uCommState)
    {
        return QObject::tr("故障");
    }
    else
    {
        return QObject::tr("正常");
    }
}

void CLedData::InitToInvalid()
{
    InitToValue(0xFFFF, FLT_MAX);
}

void CLedData::InitToZero()
{
    InitToValue(0, 0.0);
}

void CLedData::InitToValue(quint16 uvalue, float fvalue)
{
    m_uCommState = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = uvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = fvalue;
    }

    //转发的100个UINT16数据
    m_uRunState = uvalue;
    m_uFaultState = uvalue;
    m_uAlarmState = uvalue;
    m_uSwitchState = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = uvalue;
    }

    //转发的100个FLOAT数据
    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = fvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_fSetData); ++i)
    {
        m_fSetData[i] = fvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_fSetDataCopy); ++i)
    {
        m_fSetDataCopy[i] = fvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = uvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = uvalue;
    }
}
